async function getData() {
    let res = await fetch('http://localhost:3001/categorys?key=${key}&categoryId=${categoryId}');
    console.log(res);

    let json = await res.json();
    console.log(json);

    let container = document.getElementById('categorys');
    json.forEach(item => {
        let itemDiv = document.createElement('div');
        itemDiv.className = 'category-item'; // 添加类名

        if (item.level === 2) { // 判断是否为二级分类
                itemDiv.className = 'category-item2'; // 添加类名
            } else if (item.level == 1){
                itemDiv.className = 'category-item1'; // 添加类名
            }


        if (item.level === 2) { // 判断是否为二级分类
            let img = document.createElement('img');
            img.src = 'http://localhost:3001'+item.img;
            itemDiv.appendChild(img);

        }else if (item.level == 1){
            itemDiv.style.backgroundColor = 'rgb(149, 153, 143)';
        }

        let name = document.createElement('p');
        name.textContent = item.name;
        itemDiv.appendChild(name)

        container.appendChild(itemDiv);
    });
}
getData();

